package com.frx.sort.countsprt;

import java.util.Arrays;

/**
 * @author ：frx
 * @date ：Created in 2019/10/28 21:55
 * @description：ToDO
 * @modified By：
 * @version: ToDO
 */
public class TestOne {

    public static void main(String[] args){
        /**int[] arr = {2,5,3,0,2,3,0,3};*/
        /*int[] arr = {6,5,5,3,2,2,0,0,1};*/
        int[] arr = {5,6,3,2,3,1,0};
        sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void sort(int[] arr){
        int max = 0;
        int min = 0;
        for (int i=0;i<arr.length;i++){
            if (arr[i] < min){
                min = arr[i];
            }
            if (arr[i] > max){
                max = arr[i];
            }
        }
        int[] tmpArr = new int[max-min+1];
        for (int i=0;i<arr.length;i++){
            tmpArr[arr[i]]++;
        }
        System.out.println(Arrays.toString(tmpArr));
        for (int i=1;i<tmpArr.length;i++){
            tmpArr[i] = tmpArr[i] + tmpArr[i-1];
        }
        System.out.println(Arrays.toString(tmpArr));

        int[] newArr = new int[arr.length];

        for (int i=0;i<arr.length;i++){
            int index = arr[i];
            int count = tmpArr[index];
            newArr[count - 1] = index;
            tmpArr[index]--;
        }
        for (int i=0;i<arr.length;i++){
            arr[i] = newArr[i];
        }

    }

}
